﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.PartsModel
{
    public partial class PartsRankList : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "PartsRankList";
            }
        }
        #region 属性 (查询条件)


        protected string CardName
        {
            get
            {
                return GetRequestValue<string>("CardName", "");

            }
        }
        protected string RankYear
        {
            get
            {
                return GetRequestValue<string>("RankYear", "");

            }
        }



        protected override string orderField
        {
            get
            {
                return string.IsNullOrEmpty(base.orderField) ? "RID" : base.orderField;
            }
        }
        protected override string orderDirection
        {
            get
            {
                return string.IsNullOrEmpty(base.orderDirection) ? "Desc" : base.orderDirection;
            }
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "delete")
            {
                delete();
            }

            DataBind();
         //   this.AddLog(Permission.查看, GetSql());
        }
        protected void delete()
        {
          
            int rid = GetRequestValue<int>("rid", 0);
          

            bool r = PartsRankController.Delete(rid);
            if (r)
            {             
                SuccessJson("成功删除");
            }
            else
            {
                AlertJson("删除失败");
            }
        }

        protected void DataBind()
        {

            this.rpMenu.DataSource = PartsRankController.GetPagination(GetSql(), pageNum, numPerPage, SQLSort, ref TotalCount);
            this.rpMenu.DataBind();
        }
        protected string GetSql()
        {
            string wheresql = "";


            string ItemCodeSQL = "";
            if (!string.IsNullOrEmpty(CardName))
            {
                ItemCodeSQL = string.Format(" CardName LIKE '%{0}%'", CardName);
                wheresql = (string.IsNullOrEmpty(wheresql) ? "" : "and ") + ItemCodeSQL;
               
            }

            if (!string.IsNullOrEmpty(RankYear))
            {
                ItemCodeSQL = string.Format(" RankYear = '{0}'", RankYear);
                wheresql += (string.IsNullOrEmpty(wheresql) ? "" : "and ") + ItemCodeSQL;

            }
            return wheresql;
        }
    }
}